package com.scroll.demo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;

import com.scroll.demo.adapter.VerticalAdapter;
import com.scroll.demo.bean.ClassBean;
import com.scroll.demo.bean.StudentBean;
import com.scroll.demo.widget.VerticalRecyclerView;

import java.util.ArrayList;
import java.util.Random;

/**
 * Created by yingzi on 2017/6/26.
 */

public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {
    private SwipeRefreshLayout mSwipeRefreshLayout;
    private ArrayList<ClassBean> dataSet = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initData();
        initView();
    }

    private void initView() {
        VerticalRecyclerView mVerticalRecyclerView = (VerticalRecyclerView) findViewById(R.id.recyclerView);
        mVerticalRecyclerView.setLayoutManager(new LinearLayoutManager(this));

        mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeLayout);
        mSwipeRefreshLayout.setOnRefreshListener(this);

        VerticalAdapter mVerticalAdapter = new VerticalAdapter(dataSet);
        mVerticalRecyclerView.setAdapter(mVerticalAdapter);

    }

    @Override
    public void onRefresh() {
        mSwipeRefreshLayout.setRefreshing(false);
    }

    /*初始化数据 start*/
    private void initData() {
        for (int i = 0; i < 7; i++) {
            ArrayList<StudentBean> studentBeans = new ArrayList<>();
            for (int j = 0; j < 9; j++) {
                studentBeans.add(new StudentBean(getLastName() + getFirstName(), (int) (Math.random() * 20)));
            }
            dataSet.add(new ClassBean(studentBeans, "第180" + i + "班"));
        }
    }

    String lastName[] = new String[]{"赵", "钱", "孙", "李", "周", "吴", "郑", "王"};

    private String getLastName() {
        return lastName[new Random().nextInt(lastName.length)];
    }

    String firstName[] = new String[]{"望雨", "昌盛", "润", "铭", "吉", "春龙", "玉明", "富文"};

    private String getFirstName() {
        return firstName[new Random().nextInt(firstName.length)];
    }
    /*初始化数据 end*/

}
